package com.dwm716.shorturl.controller;

import com.dwm716.shorturl.common.ApiResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by wilson on 2025/2/3.
 */
@ControllerAdvice
public class GlobalExceptionController {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ApiResponse<Object> handleAllExceptions(Exception ex) {
        ApiResponse<Object> apiResponse = new ApiResponse<Object>();
        apiResponse.setCode(500);
        apiResponse.setMsg(ex.getMessage());
        return apiResponse;
    }

}
